package com.tr.rentcar.controller.houtai.admin;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.model.bean.Admin_he;
import com.tr.rentcar.model.bean.Adminrole;
import com.tr.rentcar.model.dao.AdminDao;
import com.tr.rentcar.model.dao.AdminroleDao;

@WebServlet("/admintianjia")
public class AdmintianjiaControllor extends HttpServlet {
	AdminroleDao adminroledao = new AdminroleDao();
	AdminDao admindao = new AdminDao();
	Adminrole adminrole = new Adminrole();
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			String aname = req.getParameter("aname");
			String anickname = req.getParameter("anickname");
			String asex = req.getParameter("asex");
			String apassword = req.getParameter("apassword");
			String atel = req.getParameter("atel");
			String arname = req.getParameter("arname");
			if(aname!=null && anickname!=null && asex!=null && apassword!=null && atel!=null && arname!=null ){
				Adminrole adminrole = adminroledao.findallbyname(arname);
				Integer arid = adminrole.getAr_id();
				if (admindao.save(aname, anickname, apassword, asex, atel, arid)) {
					resp.sendRedirect(req.getContextPath() + "/houtaiadmin");
				}else{
					req.getRequestDispatcher("/WEB-INF/jsp/error.jsp").forward(req, resp);
				}
			}else{
				resp.sendRedirect(req.getContextPath() + "/houtaiadmin");
			}
		} catch (SQLException e) {
			req.getRequestDispatcher("/WEB-INF/jsp/error.jsp").forward(req, resp);
			e.printStackTrace();
		}
		
	}
}
